package com.my.design.structural.proxy.JdkProxy.testjdk;

import java.lang.reflect.*;

public class TimeHandler implements InvocationHandler {

    private Object target;

    public TimeHandler(Object target) {
        super();
        this.target = target;
    }

    @Override
    public Object invoke(Object object, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
        long starttime = System.currentTimeMillis();
        System.out.println("开始记录时间");
        Object o = method.invoke(target,args);
        long endtime = System.currentTimeMillis();
        System.out.println("耗时：" + (endtime - starttime) + "毫秒！");
        return o;
    }

}